package net.flyinggroup.pagination.session;

import net.flyinggroup.pagination.event.Event;
import org.springframework.data.domain.Limit;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Window;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.graphql.data.query.ScrollSubrange;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Optional;

@Controller
public class SessionController {
    private final SessionRepository sessionRepository;

    public SessionController(SessionRepository sessionRepository) {
        this.sessionRepository = sessionRepository;
    }

    @QueryMapping
    public List<Session> sessions() {
        return sessionRepository.findAll();
    }
    @QueryMapping
    public Optional<Session> session(Integer id) {
        return sessionRepository.findById(id);
    }

//    @SchemaMapping
//    public Window<Session> sessions(Event event, ScrollSubrange scrollSubrange) {
//        ScrollPosition scrollPosition = scrollSubrange.position().orElse(ScrollPosition.offset());
//        Limit limit = Limit.of(scrollSubrange.count().orElse(10));
//        Sort sort = Sort.by("title").ascending();
//        return sessionRepository.findByEventId(event.getId(), scrollPosition, limit, sort);
//    }
}
